<template>
	<view class="big">
		<view class="uni-input-wrapper" style="margin: 15rpx;">
			<input class="uni-input" placeholder="请输入用户名" v-model="userName" />
		</view>
		<view class="uni-input-wrapper" style="margin: 15rpx;">
			<input class="uni-input" placeholder="请输入密码" v-model="pwd" />
		</view>
		<button @click="login" class="btn"> <text>登录</text> </button>
	</view>
</template>
<script>
	import { login } from '../../api/api.js'
	export default {
		data() {
			return {
				userName: '18818007814',
				pwd: 'Ty2206',
				params: '',
				user: ''
			}
		},
		methods: {
			login() {
				login({loginname: this.userName,password: this.pwd}).then(res => {
					uni.setStorageSync('userName', this.userName);
					uni.setStorageSync('pwd', this.pwd);
					uni.setStorageSync('token', res.data.data.token);
					uni.setStorageSync('userid', res.data.data.userid);
				})
				if (this.params == 1) {
					uni.reLaunch({
						url: "/pages/cart/cart"
					})
				} else if (this.user == 'a') {
					uni.reLaunch({
						url: '/pages/user/user'
					})
				} else {
					uni.navigateBack({
						delta: 1,
					})
				}
			}
		},
		onLoad(query) {
			this.params = query.num
			this.user = query.a
		}
	}
</script>
<style lang="scss">
	.big {
		margin-top: 40rpx;
	}

	.btn {
		width: 95vw;
		height: 7vh;
		border-radius: 15rpx;
		// padding-top: 20rpx;
		margin: 50rpx auto;
		display: flex;
		justify-content: center;
		align-items: center;
		background-color: orangered;
		color: #fff;
		font-size: 35rpx;

	}
</style>